package com.candy.udpdemo;

import java.io.*;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.util.Scanner;

/**
 * @author donglin
 * @Title:
 * @类名: ClientThread
 * @date 2020/6/3
 */
public class ClientThread extends Thread{
    //属性
    private DatagramSocket socket;

    public ClientThread() {
        super("客户端：");
    }

    @Override
    public void run() {

        try {
            //初始化客户端DatagramSocket
            socket=new DatagramSocket();
            ////////////////////////////////////////发送消息//////////////////////////////////
            //输出内容到网络，发送到服务器端
            String strSendSmg="你好，我是客户端";
            //将需要发送的消息打包到数据包中
            DatagramPacket dp=new DatagramPacket(strSendSmg.getBytes(),
                    strSendSmg.getBytes().length,new InetSocketAddress("127.0.0.1",9999));
            socket.send(dp);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
